from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-07 14:02:30.899096
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 07, Jun, 2022
Time: 14:02:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5330
Nobs: 680.000 HQIC: -49.8998
Log likelihood: 8450.80 FPE: 1.69117e-22
AIC: -50.1315 Det(Omega_mle): 1.48295e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307613 0.059218 5.195 0.000
L1.Burgenland 0.106421 0.038396 2.772 0.006
L1.Kärnten -0.109300 0.020218 -5.406 0.000
L1.Niederösterreich 0.200000 0.079986 2.500 0.012
L1.Oberösterreich 0.119792 0.078905 1.518 0.129
L1.Salzburg 0.255141 0.040893 6.239 0.000
L1.Steiermark 0.047673 0.053582 0.890 0.374
L1.Tirol 0.106011 0.043370 2.444 0.015
L1.Vorarlberg -0.061295 0.038157 -1.606 0.108
L1.Wien 0.032432 0.070032 0.463 0.643
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.041736 0.125427 0.333 0.739
L1.Burgenland -0.033504 0.081324 -0.412 0.680
L1.Kärnten 0.039958 0.042822 0.933 0.351
L1.Niederösterreich -0.182217 0.169414 -1.076 0.282
L1.Oberösterreich 0.440302 0.167125 2.635 0.008
L1.Salzburg 0.285350 0.086614 3.295 0.001
L1.Steiermark 0.108173 0.113490 0.953 0.341
L1.Tirol 0.315389 0.091860 3.433 0.001
L1.Vorarlberg 0.026331 0.080818 0.326 0.745
L1.Wien -0.033966 0.148331 -0.229 0.819
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187445 0.030383 6.169 0.000
L1.Burgenland 0.088195 0.019700 4.477 0.000
L1.Kärnten -0.007571 0.010373 -0.730 0.465
L1.Niederösterreich 0.256869 0.041039 6.259 0.000
L1.Oberösterreich 0.147451 0.040484 3.642 0.000
L1.Salzburg 0.044870 0.020981 2.139 0.032
L1.Steiermark 0.025745 0.027492 0.936 0.349
L1.Tirol 0.086532 0.022252 3.889 0.000
L1.Vorarlberg 0.052801 0.019577 2.697 0.007
L1.Wien 0.118704 0.035932 3.304 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110443 0.030614 3.608 0.000
L1.Burgenland 0.043376 0.019849 2.185 0.029
L1.Kärnten -0.013759 0.010452 -1.316 0.188
L1.Niederösterreich 0.185920 0.041350 4.496 0.000
L1.Oberösterreich 0.318082 0.040791 7.798 0.000
L1.Salzburg 0.102977 0.021140 4.871 0.000
L1.Steiermark 0.109984 0.027700 3.971 0.000
L1.Tirol 0.098983 0.022421 4.415 0.000
L1.Vorarlberg 0.062594 0.019726 3.173 0.002
L1.Wien -0.019555 0.036204 -0.540 0.589
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121532 0.056485 2.152 0.031
L1.Burgenland -0.046222 0.036624 -1.262 0.207
L1.Kärnten -0.046204 0.019285 -2.396 0.017
L1.Niederösterreich 0.145907 0.076294 1.912 0.056
L1.Oberösterreich 0.152783 0.075263 2.030 0.042
L1.Salzburg 0.282215 0.039006 7.235 0.000
L1.Steiermark 0.053867 0.051109 1.054 0.292
L1.Tirol 0.166984 0.041368 4.037 0.000
L1.Vorarlberg 0.096131 0.036396 2.641 0.008
L1.Wien 0.075301 0.066800 1.127 0.260
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061786 0.044630 1.384 0.166
L1.Burgenland 0.030163 0.028938 1.042 0.297
L1.Kärnten 0.051646 0.015237 3.389 0.001
L1.Niederösterreich 0.205663 0.060282 3.412 0.001
L1.Oberösterreich 0.310180 0.059468 5.216 0.000
L1.Salzburg 0.042456 0.030820 1.378 0.168
L1.Steiermark 0.009940 0.040383 0.246 0.806
L1.Tirol 0.133364 0.032686 4.080 0.000
L1.Vorarlberg 0.067421 0.028757 2.344 0.019
L1.Wien 0.087846 0.052780 1.664 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170106 0.053474 3.181 0.001
L1.Burgenland 0.006332 0.034671 0.183 0.855
L1.Kärnten -0.065079 0.018257 -3.565 0.000
L1.Niederösterreich -0.090710 0.072227 -1.256 0.209
L1.Oberösterreich 0.194183 0.071251 2.725 0.006
L1.Salzburg 0.055645 0.036926 1.507 0.132
L1.Steiermark 0.240222 0.048384 4.965 0.000
L1.Tirol 0.503904 0.039163 12.867 0.000
L1.Vorarlberg 0.060119 0.034455 1.745 0.081
L1.Wien -0.072586 0.063239 -1.148 0.251
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.152912 0.059673 2.562 0.010
L1.Burgenland 0.000762 0.038691 0.020 0.984
L1.Kärnten 0.060714 0.020373 2.980 0.003
L1.Niederösterreich 0.190465 0.080601 2.363 0.018
L1.Oberösterreich -0.075593 0.079512 -0.951 0.342
L1.Salzburg 0.209654 0.041208 5.088 0.000
L1.Steiermark 0.133839 0.053994 2.479 0.013
L1.Tirol 0.074112 0.043704 1.696 0.090
L1.Vorarlberg 0.143108 0.038450 3.722 0.000
L1.Wien 0.111984 0.070570 1.587 0.113
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375040 0.035060 10.697 0.000
L1.Burgenland -0.002488 0.022733 -0.109 0.913
L1.Kärnten -0.022083 0.011970 -1.845 0.065
L1.Niederösterreich 0.214935 0.047356 4.539 0.000
L1.Oberösterreich 0.221517 0.046716 4.742 0.000
L1.Salzburg 0.041211 0.024211 1.702 0.089
L1.Steiermark -0.015793 0.031724 -0.498 0.619
L1.Tirol 0.097625 0.025678 3.802 0.000
L1.Vorarlberg 0.056105 0.022591 2.484 0.013
L1.Wien 0.035832 0.041463 0.864 0.387
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037560 0.123850 0.183093 0.146435 0.106164 0.089929 0.043043 0.213072
Kärnten 0.037560 1.000000 -0.018174 0.134436 0.053210 0.092333 0.440056 -0.058868 0.094412
Niederösterreich 0.123850 -0.018174 1.000000 0.328927 0.134161 0.287274 0.083254 0.169750 0.306720
Oberösterreich 0.183093 0.134436 0.328927 1.000000 0.224340 0.314398 0.174214 0.160593 0.258234
Salzburg 0.146435 0.053210 0.134161 0.224340 1.000000 0.133655 0.104152 0.121223 0.133843
Steiermark 0.106164 0.092333 0.287274 0.314398 0.133655 1.000000 0.145384 0.124448 0.057959
Tirol 0.089929 0.440056 0.083254 0.174214 0.104152 0.145384 1.000000 0.081820 0.152910
Vorarlberg 0.043043 -0.058868 0.169750 0.160593 0.121223 0.124448 0.081820 1.000000 0.016734
Wien 0.213072 0.094412 0.306720 0.258234 0.133843 0.057959 0.152910 0.016734 1.000000